<?php
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
// DLMan by Shedd Technologies International		  				//
// http://www.dlman.com | info@dlman.com							//
// Copyright 2003 by STI, All rights reserved.						//
// ---------------------------------------------------------------- //
// Usage of this software is governed by the terms of GPL. 	    	//
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//

require_once("global.php");
ob_start();//start content buffer
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
	include("main_CONTENT.html");
	//Do Stats
	$sql="SELECT ".$config->field['lastactivity']." FROM ".$config->dt['user']." WHERE ".$config->field['username']."='".$HTTP_SESSION_VARS["Suser"]."'";
	$result=mysql_query($sql);
	$value=mysql_fetch_array($result);
	$last_active=$value[$config->field['lastactivity']];
	//grab total transactions
	$sql="SELECT * FROM ".$config->dt['transactions']." WHERE status='ACTIVE'";
	$result=mysql_query($sql);
	$total=mysql_num_rows($result);
	//grab recent transactions
	$sql="SELECT * FROM ".$config->dt['transactions']." WHERE timestamp>'$last_active' AND status='ACTIVE'";
	$result=mysql_query($sql);
	$recent=mysql_num_rows($result);
	//grab total clients
	$sql="SELECT ".$config->field['userid']." FROM ".$config->dt['user'];
	$result=mysql_query($sql);
	$clients=mysql_num_rows($result);
	//gross income
	$sql="SELECT cost,timestamp FROM ".$config->dt['transactions'].", ".$config->dt['files']." WHERE ".$config->dt['transactions'].".file_id = ".$config->dt['files'].".id AND ".$config->dt['transactions'].".status='ACTIVE'";
	$result=mysql_query($sql);
	$gross=0;
	while($value=mysql_fetch_array($result)){
		$gross+=$value['cost'];
	}//end while
	//output
	print '<hr size="1" color="Black">';
	print "<div align='center'>";
	?>
		<b><u>System Statistics</u></b>
		<table width="300" border="0" cellspacing="0" cellpadding="2" align="center">
			<tr>
				<td width="60%" height="15" align="center" nowrap><b>Gross Revenue:</b></td><td width="40%" height="15" align="center" nowrap>$<?php print sprintf("%.2f",$gross); ?>&nbsp;<b>*</b></td>
			</tr>
			<tr>
				<td width="60%" height="15" align="center" nowrap><b>Recent Transactions:</b></td><td width="40%" height="15" align="center" nowrap><?php print $recent; ?>&nbsp;<b>**</b></td>
			</tr>
			<tr>
				<td width="60%" height="15" align="center" nowrap><b>Total Transactions:</b></td><td width="40%" height="15" align="center" nowrap><?php print $total ?></td>
			</tr>
			<tr>
				<td width="60%" height="15" align="center"><b>Recent Transaction's Percent of Total:</b></td><td width="40%" height="15" align="center" nowrap><?php print recent_table($recent,$total); ?></td>
			</tr>
			<tr>
				<td width="60%" height="15" align="center" nowrap><b>Total Registered Clients:</b></td><td width="40%" height="15" align="center" nowrap><?php print $clients ?></td>
			</tr>
		</table>
	<?php
	print "</div>";
	print "<p><b>*</b>&nbsp;Based on current value of products<br>";
	print "<b>**</b>&nbsp;Since your last visit</p>";
	print '<hr size="1" color="Black">';
	$now=getdate();
	if(!isset($month)) $month=$now['mon'];
	if(!isset($year)) $year=$now['year'];
	print transaction_calendar($month,$year);
	print '<hr size="1" color="Black">';
	//update last activity
	$sql="UPDATE ".$config->dt['user']." SET ".$config->field['lastactivity']."='".time()."' WHERE ".$config->field['username']."='".$HTTP_SESSION_VARS["Suser"]."'";
	$result=mysql_query($sql);
	if(!$result) print "<!--Unable to update last activity! -- $sql -- ".mysql_error()."-->";
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
$content=ob_get_contents();//store content to global buffer var
ob_end_clean();
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
function recent_table($recent,$total){
	if($total!=0){
		$per=(100*($recent/$total));
	}
	else{
		$per=0;
	}
	?>
		<!--Recent Percent of Total TABLE-->
		<table width="80%" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td bgcolor="#666666" height="10"><table width="<?php print $per; ?>%" border="0" cellspacing="0" cellpadding="0"><tr><td height="10" bgcolor="#cbcbcb"></td></tr></table></td></tr></table></td><td width="10%" height="15"><?php print $per; ?>%</td>
		<!--END Recent Percent of Total TABLE-->
	<?php
}//end recent_table function
//-------------------------------------------------------------------------------
function transaction_calendar($month,$year){
	require("calendar.php");
	?>
	<style>
	.today{
	    border-top:1px solid;
	    border-bottom:1px solid;
	    border-left: 1px solid;
	    border-right:1px solid;
	    BORDER-COLOR: Black;
	}
	</style>
	<script language="JavaScript" type="text/javascript">
		//configure status message to show
		function dstatus(statusmsg){
			window.status=statusmsg;
			return true;
		}
	</script>
	<a name="cal"></a>
	<div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">
	<table width="100%" align="center" bgcolor="black" cellspacing="0" cellpadding="0" border="0">
	<tr>
		<!--calendar-->
		<td bgcolor="black">
			<table width="100%" cellspacing=1 cellpadding=2 border="0">
			<tr>
				<td bgcolor="white"><?php print calendar($month,$year); ?></td>
			</tr>
			</table>
		</td>
		<!--END calendar-->
	</tr>
	</table>
	</font></div>
	<?php
}
//-------------------------------------------------------------------------------
?>
